// 厦门大学计算机专业 | 前华为工程师
// 专注《零基础学编程系列》https://cxyxy.blog.csdn.net/article/details/121134634
// 包含：Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙
// 公众号：蓝不蓝编程

import Foundation

enum stopWatchMode {
    case running
    case stopped
    case paused
}

class Stopwatch: ObservableObject {
    
    @Published var mode: stopWatchMode = .stopped
    @Published var seconds = 0.0
    
    var timer = Timer()
    
    func start() {
        mode = .running
        timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true)
        { timer in
            self.seconds = self.seconds + 0.1
        }
    }
    
    func pause() {
        timer.invalidate()
        mode = .paused
    }
    
    func stop() {
        timer.invalidate()
        seconds = 0
        mode = .stopped
    }
    
}
